home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / CPX / MODEM.TC / MODEM.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  29.5 KB  |  1,228 lines

  1. /* MODEM.C
  2.  *==========================================================================
  3.  * DATE: March 9, 1990
  4.  *     January 14, 1993   Handle new 3D format
  5.  * DESCRIPTION: MODEM CPX
  6.  */
  7.  
  8. /* There are now 4 ports on the TT versus 1 port on an ST/STe/Mega
  9.  * There are also 3 ports on the Mega STE
  10.  *
  11.  * Rsconf( -2, -1, -1, -1, -1 ) with TOS 1.4 or greater will return
  12.  *                 the current Baud rate 0-15 in the low word
  13.  *
  14.  * Rsconf( -1, -1, -1, -1, -1 ) will return a long containing the
  15.  *                 UCR, RSR, TSR and SCR in that order.
  16.  *
  17.  * UCR defines are:
  18.  *    7    6    5    4    3    2    1    0      bits
  19.  *     ---     ---     ---     ---     ---     ---     ---     ---     ----
  20.  *     Don't  |           |   |          |    |      |    unused
  21.  *     Touch  |           |   |           |    |          |
  22.  *            |___________|   |___________|    |__________|
  23.  *                  |               |                |
  24.  *                  |               |              PARITY
  25.  *            |               |            2  1
  26.  *            |               |           ------
  27.  *                  |               |            0  0      No   Parity
  28.  *                  |               |            0  1      No   Parity
  29.  *                  |               |            1  0      Odd  Parity  
  30.  *            |               |            1  1      Even Parity
  31.  *                  |            Stop Bits
  32.  *            |            4  3
  33.  *            |          ------
  34.  *            |           0  0    0   Stop Bits
  35.  *            |           0  1    1   Stop Bits
  36.  *            |            1  0    1.5 Stop Bits
  37.  *            |           1  1    2   Stop Bits
  38.  *            | 
  39.  *              Word Length
  40.  *           6  5
  41.  *          ------
  42.  *             0  0   8 bits
  43.  *             0  1   7 bits
  44.  *             1  0   6 bits
  45.  *             1  1   5 bits
  46.  *
  47.  * On a TT ONLY, done by checking the cookie for _MCH == 0x2xxxxL
  48.  * we can call:
  49.  *               xbios( (int)0x2c, PORT# );
  50.  *
  51.  * to switch the serial port mask.
  52.  * MEGA STE is 0x10010L
  53.  * The port numbers are:                        On Box
  54.  *                              6    ST Serial Port ( 68901 )    Modem 1
  55.  *                    7     Channel B      ( SCC chip )    Modem 2
  56.  *                8    TT Serial Port ( 68901 )    Serial 1
  57.  *                9    Channel A      ( SCC chip )    Serial 2
  58.  *                   -1       Return current setting
  59.  * When calling this routine, it returns the previous setting.
  60.  *
  61.  * MODEM.CP Settings:
  62.  *
  63.  *
  64.  *      BAUD RATE:        0    -   19200 baud
  65.  *                     ...
  66.  *                15   -   50 baud
  67.  *
  68.  *      FLOW CONTROL:   0   -    None
  69.  *                1   -   Xon/Xoff
  70.  *            2   -   Rts/Cts
  71.  *
  72.  *   See the corresonding UCR values. MODEM.CP will adjust these to match
  73.  *   whenever it reads/writes to the ports.
  74.  *
  75.  *      Parity:            0   -    None
  76.  *            1   -   Odd
  77.  *            2   -   Even
  78.  *
  79.  *      Stop Bits:    0   -   0   Stop Bits
  80.  *            1   -   1   Stop Bits
  81.  *            2   -   1.5 Stop Bits
  82.  *            3   -   2   Stop Bits
  83.  * 
  84.  *      Word Length:    0   -   8 Bits/Char
  85.  *                      1   -   7
  86.  *                      2   -   6
  87.  *                      3   -   5
  88.  *
  89.  * LAN PORT - If on a TT or MEGA STE, Channel A can either be
  90.  *          a serial port or the LAN port.
  91.  *
  92.  *        - Bit 7 of the PSG determines this
  93.  *          Bit 7 == 1 ==>   Use as Serial Port
  94.  *          Bit 7 == 0 ==>   LAN IN USE
  95.  *
  96.  *        - When the LAN is in use, do not read or write to
  97.  *          Channel A
  98.  */
  99.  
  100.  
  101. /* INCLUDE FILES 
  102.  *==========================================================================
  103.  */
  104. #include <sys\gemskel.h>
  105. #include <tos.h>
  106. #include <string.h >
  107.  
  108. #include "country.h"
  109.  
  110. #include "struct.h"
  111.  
  112. #include "modem.h"
  113. #include "modem.rsh"
  114.  
  115. #include "..\cpxdata.h"
  116. #include "ports.h"
  117.  
  118.  
  119. /* PROTOTYPES
  120.  *==========================================================================
  121.  */
  122. CPXINFO    *cdecl cpx_init( XCPB *Xcpb );
  123. BOOLEAN  cdecl cpx_call( GRECT *rect );
  124.  
  125. void     set_objects( int port );
  126.  
  127. int      Pop_Handle( int button, char *items[], int num_items,
  128.                      int *default_item, int font_size, int width );
  129.  
  130. void     push_data( void );
  131. void      pop_data( void );
  132.  
  133.  
  134. BOOLEAN  IsTT( void );
  135. BOOLEAN  IsSTE( void );
  136. void     Select_Ok( void );
  137.  
  138. void     Set_Machine_Code( void );
  139.  
  140. long     Get_OS( void );
  141. BOOLEAN  Check_OS( void );
  142.  
  143. void     Redraw_Objects( void );
  144. void     do_redraw( OBJECT *tree, int obj );
  145.  
  146. BOOLEAN  IsLanActive( void );
  147. void     Set_Number_Of_Ports( void );
  148.  
  149. int     Get_Active_Port( void );
  150. int     Set_Active_Port( int cur_port );
  151.  
  152. void     Check_Port_Change( void );
  153.  
  154. void     close_vwork(void);
  155. void      open_vwork( void );
  156. void     MakeActivator( int xtree, int obj );
  157.  
  158.  
  159. /* DEFINES
  160.  *==========================================================================
  161.  */
  162. #define PORT_A        0
  163. #define PORT_B        1
  164. #define PORT_C        2
  165. #define PORT_D        3
  166.  
  167. /* Machine Code Values */
  168. #define ST        0L
  169. #define TT        2L
  170. #define MEGA_STE    0x10010L
  171.  
  172. /* Maximum Number of Serial Ports currently possible */
  173. #define MAX_PORTS    4
  174. #define MACHINE_COOKIE  0x5f4d4348L
  175.  
  176.  
  177. /* Bconmap Devices
  178.  *-----------------------------------------------------------------
  179.  * MASK_A  -->        ST Serial: All Machines
  180.  * MASK_B  -->        Channel B: TT and Mega STE
  181.  * MASK_C  -->        (TT): TT Serial
  182.  * MASK_D  -->        (TT): Channel A
  183.  */
  184. #define INQUIRE_MAP    -1
  185.  
  186. #define MASK_A        6
  187. #define MASK_B        7
  188. #define MASK_C        8
  189. #define MASK_D        9
  190.  
  191. /* TOS 1.4 Cookie Check */
  192. #define TOS14        0x0104
  193.  
  194.  
  195.  
  196. /* Number of Ports Possible 
  197.  * When Channel A is Set for LAN, it cannot be used as a serial port
  198.  */
  199. #define NORMAL_ST    1
  200.  
  201. #define TT_LAN        3
  202. #define TT_NO_LAN    4
  203.  
  204. #define MEGA_STE_LAN    2
  205. #define MEGA_STE_NO_LAN 3
  206.  
  207. #define MEGA_STE_PORTS    2
  208.  
  209. #define Bconmap( xport )    ( int )xbios( 0x2c, ( xport ) )
  210.      
  211.  
  212.  
  213. /* EXTERNALS
  214.  *==========================================================================
  215.  */
  216. extern MDEFAULT  save_vars;
  217.  
  218.  
  219. /* GLOBALS
  220.  *==========================================================================
  221.  */
  222. MDEFAULT Modem;            /* Structure of 4 modem ports plus cur_port */
  223. MDEFAULT Old_Modem;        /* Backup storage for CANCEL            */
  224.  
  225. #if 0
  226. MDATA   *modemptr;
  227.  
  228.  
  229. MDATA    modem[ MAX_PORTS ];    /* Storage for current data...     */
  230. MDATA   old_modem[ MAX_PORTS ];    /* BACKUP storage for CANCEL       */
  231. #endif
  232.  
  233. int     old_port;
  234. int     cur_port;        /* Current Serial Port  - NUM_PORTS
  235.                  * 0, 1, 2, 3
  236.                  * There is only ONE port on regular STs.
  237.                  * The other ports are for the TT.
  238.                  */
  239.                  
  240. BUFFER  *store;            /* Need to store baud rate and flow cntrl
  241.                  * in the 64 byte buffer. There is no other
  242.                  * way to get these 2 numbers since they
  243.                  * are write only items. The UCR data 
  244.                  * can be had from RSCONF
  245.                  */
  246.  
  247. int top_baud;            /* Top baud rate is the item at the top
  248.                  * ( BAUD1 ) for the popup box
  249.                  */
  250.  
  251. char *baud_array[] = { "19200",
  252.                "9600",
  253.                      "4800",
  254.                     "3600",
  255.                "2400",
  256.                "2000",
  257.                "1800",
  258.                "1200",
  259.                "600",
  260.                "300",
  261.                "200",
  262.                "150",
  263.                "134",
  264.                "110",
  265.                "75",
  266.                "50"
  267.              };
  268.  
  269.  
  270.               
  271. char *bits_array[] = { "8",            /* Array for bits/char    */
  272.                "7",            /* Indexed thru cur_bits  */
  273.                "6",
  274.                "5"
  275.              };
  276.  
  277.             
  278. char *stop_array[] = { "0",           /* Array for stop bits     */
  279.                "1",           /* Indexed thru cur_stop   */
  280.                "1.5",           
  281.                "2"           
  282.              };
  283.  
  284.  
  285.  
  286. char *port_array[] = { "Modem 1",
  287.                "Modem 2",
  288.                "Serial 1",
  289.                "Serial 2"
  290.              };
  291.              
  292. /* VDI arrays */
  293. int    contrl[12], intin[128], intout[128], ptsin[128], ptsout[128],
  294.     work_in[12], work_out[57];
  295. int    vhandle=-1;        /* virtual workstation handle */
  296. int    hcnt=0;            /* handle count */
  297.  
  298.  
  299.  
  300. /*==========================================================================
  301.  * STRINGS
  302.  *==========================================================================
  303.  */
  304.  
  305. /* COUNTRY: USA | UK
  306.  *==========================================================================
  307.  */ 
  308. #if USA | UK
  309.     char *flow_array[] = { "None",       /* Array for flow control */
  310.                          "Xon/Xoff",       /* Index thru cur_flow    */
  311.                        "Rts/Cts"
  312.                      };
  313.  
  314.     char *parity_array[] = { "None",    /* Parity... */
  315.                   "Odd",
  316.                    "Even"
  317.                               };
  318. #endif
  319.  
  320.  
  321.  
  322. /* COUNTRY: ITALY
  323.  *==========================================================================
  324.  */ 
  325. #if ITALY
  326.     char *flow_array[] = { "Nessuno",       /* Array for flow control */
  327.                          "Xon/Xoff",       /* Index thru cur_flow    */
  328.                        "Rts/Cts"
  329.                      };
  330.  
  331.     char *parity_array[] = { "Nessuna",    /* Parity... */
  332.                   "Dispari",
  333.                    "Pari"
  334.                               };
  335. #endif
  336.  
  337.  
  338.  
  339.  
  340. /* COUNTRY: GERMAN
  341.  *==========================================================================
  342.  */ 
  343. #if GERMAN
  344.     char *flow_array[] = { "Keine",       /* Array for flow control */
  345.                          "Xon/Xoff",       /* Index thru cur_flow    */
  346.                        "Rts/Cts"
  347.                      };
  348.  
  349.     char *parity_array[] = { "Keine",    /* Parity... */
  350.                   "Ungerade",
  351.                    "Gerade"
  352.                               };
  353. #endif
  354.  
  355.  
  356.  
  357.  
  358. /* COUNTRY: FRENCH
  359.  *==========================================================================
  360.  */ 
  361. #if FRENCH
  362.     char *flow_array[] = { "Sans",       /* Array for flow control */
  363.                          "Xon/Xoff",       /* Index thru cur_flow    */
  364.                        "Rts/Cts"
  365.                      };
  366.  
  367.     char *parity_array[] = { "Sans",    /* Parity... */
  368.                   "Impaire",
  369.                    "Paire"
  370.                               };
  371. #endif
  372.  
  373.  
  374.  
  375.  
  376. /* COUNTRY: SPAIN
  377.  *==========================================================================
  378.  */ 
  379. #if SPAIN
  380.     char *flow_array[] = { "No",           /* Array for flow control */
  381.                          "Xon/Xoff",       /* Index thru cur_flow    */
  382.                        "Rts/Cts"
  383.                      };
  384.  
  385.     char *parity_array[] = { "No",        /* Parity... */
  386.                   "Impar",
  387.                    "Par"
  388.                               };
  389. #endif
  390.  
  391.  
  392.  
  393.  
  394.  
  395. /* COUNTRY: SWEDEN
  396.  *==========================================================================
  397.  */ 
  398. #if SWEDEN
  399.     char *flow_array[] = { "Ingen",       /* Array for flow control */
  400.                          "Xon/Xoff",       /* Index thru cur_flow    */
  401.                        "Rts/Cts"
  402.                      };
  403.  
  404.     char *parity_array[] = { "Ingen",    /* Parity... */
  405.                   "Udda",
  406.                    "Jämn"
  407.                               };
  408. #endif
  409.  
  410.  
  411.  
  412.  
  413.  
  414. /* GLOBALS
  415.  *==========================================================================
  416.  */ 
  417. char blanks[20][20];    /* Used for Pop_Up String Manipulation  */
  418. char *blank[20];    /* and is subject to change after review*/
  419.  
  420. XCPB    *xcpb;        /* Structure of function pointers FROM XCONTROL */
  421. CPXINFO cpxinfo;    /* Structure of function pointers TO XCONTROL   */
  422.  
  423. long    machine_code;    /* Machine Code from Cookie Check */
  424.  
  425. unsigned int version;    /* TOS rom version */         
  426.  
  427. int    Num_Ports;    /* Number of ACTUAL ports that the CPX can use
  428.              * This can be as high as 4 on a TT,
  429.              * 3 on a MEGA STE, and 1 on all other STs
  430.              * If LAN is active for TT or MEGA STE,
  431.              * Active number of ports is 1 less.
  432.              * See IsLanActive() for LAN Detection
  433.              */
  434. /*             
  435. int    stack_port;    * the port that is shoved during a push_data()
  436.              * and is used for a pop_data. (mainly for OK and
  437.              * cancel functions )
  438.              *
  439. */
  440.  
  441. int AES_Version;
  442. int gl_ncolors;
  443.  
  444.  
  445. /* FUNCTIONS
  446.  *==========================================================================
  447.  */
  448.  
  449.  
  450. /* cpx_init() 
  451.  *==========================================================================
  452.  * Initialize cpx data structures etc...
  453.  */
  454. CPXINFO
  455. *cdecl cpx_init( XCPB *Xcpb )
  456. {
  457.     OBJECT *tree;
  458.     int    port;
  459.     int    temp_port;
  460.     
  461.     xcpb = Xcpb;
  462.     if( xcpb->booting )
  463.     {
  464.         /* Read in defaults and set the options */
  465.  
  466.         store = ( BUFFER *)(*xcpb->Get_Buffer)();
  467.         Modem = save_vars;
  468.         
  469.         Set_Machine_Code();
  470.     Set_Number_Of_Ports();        
  471.     
  472.         for( port = 0; port < Num_Ports; port++ )
  473.         {
  474.        Write_Port( port, store );
  475.        store++;
  476.         }
  477.         Modem.cur_port = Set_Active_Port( Modem.cur_port );
  478.         return( ( CPXINFO *)TRUE );  
  479.     }
  480.     else
  481.     {
  482.       appl_init();
  483.       AES_Version = _GemParBlk.global[0];
  484.       
  485.       if( !xcpb->SkipRshFix )
  486.            (*xcpb->rsh_fix)( NUM_OBS, NUM_FRSTR, NUM_FRIMG, NUM_TREE,
  487.                        rs_object, rs_tedinfo, rs_strings, rs_iconblk,
  488.                        rs_bitblk, rs_frstr, rs_frimg, rs_trindex,
  489.                        rs_imdope );
  490.  
  491.  
  492.       Supexec( Get_OS );
  493.       tree = ( OBJECT *)rs_trindex[ RS232 ];
  494.       Disable( PORT );
  495.       Set_Machine_Code();
  496.       (( IsTT() || IsSTE() ) ? ( Enable( PORT ) ) : ( Disable( PORT ) ) );
  497.       Set_Number_Of_Ports();
  498.       store = ( BUFFER *)(*xcpb->Get_Buffer)();
  499.       
  500.       Modem = save_vars;    /* Get the Defaults and fill up all 4 ports with info */
  501.       
  502.       /* Get the ACTUAL system values for as many ports as possible.*/
  503.       temp_port = Get_Active_Port();
  504.       for( port = 0; port < Num_Ports; port++ )
  505.       {
  506.     Read_Port( port, store );
  507.     store++;      
  508.       }
  509.       Modem.cur_port = Set_Active_Port( temp_port );
  510.       push_data();
  511.  
  512.       open_vwork();
  513.       close_vwork();
  514.       gl_ncolors = work_out[13];
  515.  
  516.       if( !xcpb->SkipRshFix )
  517.       {
  518.         if(( AES_Version >= 0x0330 )
  519.          && ( gl_ncolors > LWHITE ))
  520.         {
  521.           tree  = (OBJECT *)rs_trindex[RS232];
  522.       MakeActivator( RS232, SAVE );
  523.       MakeActivator( RS232, RS232OK );
  524.       MakeActivator( RS232, RS232CAN );
  525.         }
  526.       }   
  527.       
  528.       
  529.       
  530.       cpxinfo.cpx_call   = cpx_call;
  531.       cpxinfo.cpx_draw   = NULL;
  532.       cpxinfo.cpx_wmove  = NULL;
  533.       cpxinfo.cpx_timer  = NULL;
  534.       cpxinfo.cpx_key    = NULL;
  535.       cpxinfo.cpx_button = NULL;
  536.       cpxinfo.cpx_m1      = NULL;
  537.       cpxinfo.cpx_m2     = NULL;
  538.       cpxinfo.cpx_hook   = NULL;
  539.       cpxinfo.cpx_close  = NULL;             
  540.       return( &cpxinfo );
  541.     }
  542. }
  543.  
  544.  
  545. /* set_objects()
  546.  *==========================================================================
  547.  * Set Button Text
  548.  */
  549. void
  550. set_objects( int port  )
  551. {
  552.      OBJECT *tree  = (OBJECT *)rs_trindex[RS232];
  553.     
  554.      
  555.      /* Setup Flow Control */
  556.      TedText( FLOW ) = flow_array[ Modem.modem[ port ].cur_flow ];
  557.           
  558.      /* Setup Baud Rate    */
  559.      TedText( BAUD ) = baud_array[ Modem.modem[ port ].cur_baud ];
  560.  
  561.      /* Setup Parity    */
  562.      TedText( PARITY ) = parity_array[ Modem.modem[ port ].cur_parity ];
  563.      
  564.      /* Setup Bits/CHAR */
  565.      TedText( BITSCHAR ) = bits_array[ Modem.modem[ port ].cur_bits ]; 
  566.      
  567.      /* Setup Stopbits */
  568.      TedText( STOPX ) = stop_array[ Modem.modem[ port ].cur_stop ];
  569.      
  570.      /* Setup Port */
  571.      TedText( PORT ) = port_array[ port ];
  572. }
  573.  
  574.  
  575.  
  576. /* cpx_call()
  577.  *==========================================================================
  578.  * Execute the cpx using Xform_do()
  579.  */
  580. BOOLEAN
  581. cdecl cpx_call( GRECT *rect )
  582. {
  583.      int button;
  584.      int quit = 0;
  585.      OBJECT *tree  = (OBJECT *)rs_trindex[RS232];
  586.      WORD msg[8];
  587.      int  temp;
  588.      int  temp_port;
  589.      long filesize;
  590.      char *a,*b;
  591.      GRECT xrect;
  592.                     
  593.      set_objects( cur_port );
  594.  
  595.      if( IsSTE() )
  596.      {
  597.         a = port_array[ PORT_C ];
  598.         b = port_array[ PORT_D ];
  599.         strcpy( a, b );
  600.      }
  601.      
  602.      ObX( ROOT ) = rect->g_x;
  603.      ObY( ROOT ) = rect->g_y;
  604.      Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
  605.      do
  606.      {
  607.     button = (*xcpb->Xform_do)( tree, 0, msg );
  608.          switch( button )
  609.          {
  610.                      /* if on a TT, we write out structure for 4 ports
  611.                       * but on an ST/STE/Mega, we write out just ONE!
  612.                       * And on a MEGA STE, we write out 3
  613.                       */
  614.              case SAVE:    if( (*xcpb->XGen_Alert)( SAVE_DEFAULTS ) )
  615.                      {
  616.                     filesize = sizeof( MDEFAULT );
  617.                     (*xcpb->CPX_Save)( &Modem, filesize );                        
  618.                         Select_Ok();
  619.                     }
  620.                     Deselect( SAVE );
  621.                     xrect = ObRect( SAVE );
  622.                     objc_offset( tree, SAVE, &xrect.g_x, &xrect.g_y );
  623.                     xrect.g_x -= 2;
  624.                     xrect.g_y -= 2;
  625.                     xrect.g_w += 4;
  626.                     xrect.g_h += 4;
  627.                     Objc_draw( tree, SAVE, MAX_DEPTH, &xrect );
  628. #if 0                        
  629.                      deselect( tree, SAVE );
  630. #endif                     
  631.                      break;
  632.                      
  633.              case RS232OK:    quit = RS232OK;
  634.                      Select_Ok();
  635.                      Deselect( RS232OK );
  636.                      break;
  637.                              
  638.              case RS232CAN:    quit = RS232CAN;
  639.                      pop_data();
  640.                      Deselect( RS232CAN );
  641.                      break;
  642.                              
  643.              case BAUD:    Pop_Handle( BAUD, baud_array, 16, &Modem.modem[ cur_port ].cur_baud, IBM, 8 );
  644.                      break;
  645.                              
  646.         case FLOW:    Pop_Handle( FLOW, flow_array, 3, &Modem.modem[ cur_port ].cur_flow, IBM, 11 );
  647.                 break;
  648.  
  649. #if FRENCH | ITALY
  650.         case PARITY:    Pop_Handle( PARITY, parity_array, 3, &Modem.modem[ cur_port ].cur_parity, IBM, 10 );
  651.                 break;
  652. #endif
  653.  
  654. #if GERMAN                
  655.         case PARITY:    Pop_Handle( PARITY, parity_array, 3, &Modem.modem[ cur_port ].cur_parity, IBM, 11 );
  656.                 break;
  657. #endif
  658.                 
  659. #if USA | UK | SPAIN | SWEDEN
  660.         case PARITY:    Pop_Handle( PARITY, parity_array, 3, &Modem.modem[ cur_port ].cur_parity, IBM, 8 );
  661.                 break;
  662. #endif
  663.                 
  664.         case BITSCHAR:    Pop_Handle( BITSCHAR, bits_array, 4, &Modem.modem[ cur_port ].cur_bits, IBM, 8 );
  665.                 break;
  666.                 
  667.         case STOPX:    if( !Modem.modem[ cur_port ].cur_stop )
  668.                    Pop_Handle( STOPX, stop_array, 4, &Modem.modem[ cur_port ].cur_stop, IBM, 8 );
  669.                 else
  670.                 { 
  671.                    temp = Modem.modem[ cur_port ].cur_stop;
  672.                    temp -= 1;
  673.                    Pop_Handle( STOPX, &stop_array[1], 3, &temp, IBM, 8 );
  674.                    Modem.modem[ cur_port ].cur_stop = temp + 1;
  675.                 }   
  676.                 break;
  677.                 
  678.         case PORT:    if( !IsDisabled( PORT ) )
  679.                 {
  680.                    /* Select number of ports based on 
  681.                     * LAN TT and MEGA STE
  682.                     * If on TT the LAN
  683.                     * is ACTIVE AND we are using CHANNEL A,
  684.                     * then set port to ST SERIAL using
  685.                     * Bconmap call.
  686.                     *
  687.                     * For the Popup, we set the number of ports and also
  688.                     * the default 'old_port' which is set by Set_Active_Port()
  689.                     
  690.                     */
  691.                    temp_port = Get_Active_Port();
  692.                    Modem.cur_port = Set_Active_Port( temp_port );
  693.                    
  694.                    Pop_Handle( PORT, port_array, Num_Ports, &old_port, IBM, 11 );
  695.                    if( old_port != cur_port )
  696.                    {
  697.                      cur_port = old_port;
  698.                      Modem.cur_port = Set_Active_Port( cur_port );
  699.                      set_objects( cur_port );
  700.                      Objc_draw( tree, BAUD, 0, NULL );
  701.                      Objc_draw( tree, FLOW, 0, NULL );
  702.                      Objc_draw( tree, PARITY, 0, NULL );
  703.                      Objc_draw( tree, BITSCHAR, 0, NULL );       
  704.                      Objc_draw( tree, STOPX, 0, NULL );
  705.                    }
  706.                 }
  707.                 break;
  708.                                 
  709.              default:    if( button == -1 )
  710.                      {
  711.                         switch( msg[0] )
  712.                         {
  713.                           case WM_REDRAW: Redraw_Objects();
  714.                                        break;
  715.  
  716.                           case AC_CLOSE:  quit = RS232CAN;
  717.                                        pop_data();
  718.                              break;
  719.                              
  720.                           case WM_CLOSED: quit = RS232OK;
  721.                                        Select_Ok();
  722.                              break;
  723.                           default:
  724.                                   break;
  725.                         }
  726.                      }
  727.                      break;
  728.          }
  729.      }while( !quit);
  730.      
  731.      return( FALSE );
  732. }
  733.  
  734.  
  735.  
  736.  
  737. /* Pop_Handle()
  738.  *==========================================================================
  739.  * Setup strings for popup menu and execute...
  740.  */
  741. int
  742. Pop_Handle( int button, char *items[], int num_items, int *default_item, int font_size, int width )
  743. {
  744.    GRECT butn, world;
  745.    
  746.    int  i;
  747.    int  obj;
  748.    long max = 0L;
  749.    OBJECT *tree = (OBJECT *)rs_trindex[ RS232 ];
  750.    int small = FALSE;
  751.  
  752.    Check_Port_Change();
  753.      
  754.    butn = ObRect( button );
  755.    objc_offset( tree, button, &butn.g_x, &butn.g_y );
  756.  
  757.    world = ObRect( ROOT );
  758.    objc_offset( tree, ROOT, &world.g_x, &world.g_y ); 
  759.    
  760.    
  761.    for( i = 0; i < num_items; i++ )
  762.    {
  763.        if( strlen( items[i] ) > max )
  764.                 max = strlen( items[i] );
  765.    }
  766.  
  767.    if( max <= 3L )
  768.        small = TRUE;
  769.               
  770.    for( i = 0; i < num_items; i++ )
  771.    {
  772.       if( small )
  773.         strcpy( &blanks[i][0], "   " );
  774.       else
  775.         strcpy( &blanks[i][0], "  ");        /* get 2 blank spaces */
  776.       strcat( &blanks[i][0], items[ i ]);    /* copy the string    */
  777.       do
  778.       {
  779.          strcat( &blanks[i][0], " ");
  780.       }while( strlen( &blanks[i][0] ) < width );
  781.       blank[i] = &blanks[i][0];
  782.    }
  783.    
  784.    obj = (*xcpb->Popup)( blank, num_items, *default_item, font_size, &butn, &world );
  785.  
  786.    if( obj != -1 )
  787.           *default_item = obj;
  788.  
  789.    TedText( button ) = items[ *default_item ];
  790.    Objc_draw( tree, button, 0, NULL );
  791.           
  792.    /* Other than the serial port mask selector...
  793.     * we will slam the new setting into the hardware at the
  794.     * current mask for the tt and into PORT_A for the ST
  795.     */
  796.    if( button != PORT )
  797.        Set_Rsconf( cur_port );
  798.    return( obj );
  799. }
  800.  
  801.  
  802.  
  803.  
  804.  
  805. /* push_data()
  806.  *==========================================================================
  807.  * Save current data to cancel buffer
  808.  */
  809. void
  810. push_data( void )
  811. {
  812.    Old_Modem = Modem;   
  813. }
  814.  
  815.  
  816.  
  817.  
  818. /* pop_data()
  819.  *==========================================================================
  820.  * Restore cancel buffer to current data
  821.  */
  822. void
  823. pop_data( void )
  824. {
  825.  
  826.    int port;
  827.    
  828.    store = ( BUFFER *)(*xcpb->Get_Buffer)();
  829.    
  830.    for ( port = 0; port < Num_Ports; port++ )
  831.    {
  832.          Modem.modem[ port ] = Old_Modem.modem[ port ];
  833.          Write_Port( port, store );
  834.          store++;
  835.    }
  836.    Modem.cur_port = Set_Active_Port( Old_Modem.cur_port );
  837. }
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845. /* Select_Ok
  846.  *==========================================================================
  847.  * Called when OK button is pressed or close_window occurs
  848.  */
  849. void
  850. Select_Ok( void )
  851. {
  852.     int port;
  853.     int temp_port;
  854.     
  855.     store = ( BUFFER *)(*xcpb->Get_Buffer)();
  856.     temp_port = Get_Active_Port();
  857.     for( port = 0; port < Num_Ports; port++ )
  858.     {
  859.        Write_Port( port, store );
  860.        store++;
  861.     }
  862.     Modem.cur_port = Set_Active_Port( temp_port );
  863.     push_data();
  864. }
  865.  
  866.  
  867.  
  868.  
  869. /* Set_Machine_Code()
  870.  *==========================================================================
  871.  * Check for _MCH cookie
  872.  * If TRUE, machine_code contains the following numbers in the HIGH WORD
  873.  *      0 - ST
  874.  *      1 - STE
  875.  *      2 - TT        0x20000L == TT
  876.  *      0x10010L - Mega STE
  877.  *
  878.  * GLOBAL: long machine_code:   Will contain the machine code value
  879.  */
  880. void
  881. Set_Machine_Code( void )
  882. {
  883.    if( (*xcpb->getcookie)( MACHINE_COOKIE, &machine_code ) )
  884.    {
  885.          return;
  886.    }         
  887.  
  888.    machine_code = ST;     
  889. }
  890.  
  891.  
  892.  
  893.  
  894. /* Get_OS()
  895.  *==========================================================================
  896.  * Supexec this routine to get the version # in the variable..'VERSION'
  897.  */
  898. long
  899. Get_OS( void )
  900. {
  901.     SYSHDR *osheader;
  902.     
  903.     osheader = *((SYSHDR **)0x4f2L );
  904.     osheader = osheader->os_base;
  905.     version  = osheader->os_version;
  906.     return( 0L );
  907. }
  908.  
  909.  
  910.  
  911. /* Check_OS()
  912.  *==========================================================================
  913.  * Return TRUE or FALSE if the version of the OS is >= than TOS 1.4
  914.  */
  915. BOOLEAN
  916. Check_OS( void )
  917. {
  918.     return( version >= TOS14 );
  919. }
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926. /* Redraw_Objects()
  927.  *==========================================================================
  928.  * Redraws the modem objects.
  929.  * This is especially important if the values are changed, therefore
  930.  * they must reflect actual reality
  931.  */
  932. void
  933. Redraw_Objects( void )
  934. {
  935.    OBJECT *tree = ( OBJECT *)rs_trindex[ RS232 ];
  936.    MDATA temp;
  937.    int   xport;
  938.    int   i;
  939.    int   temp_port;
  940.    
  941.    store = ( BUFFER *)(*xcpb->Get_Buffer)();
  942.    
  943.    xport = temp_port = Get_Active_Port();
  944.    Set_Number_Of_Ports();
  945.    temp  = Modem.modem[ temp_port ];
  946.  
  947.    for( i =0;i < Num_Ports;i++ )
  948.    {
  949.        Read_Port( i, store );
  950.        store++;   
  951.    }
  952.    Set_Active_Port( temp_port );
  953.    set_objects( cur_port );
  954.       
  955.    if( xport != cur_port )
  956.        do_redraw( tree, PORT );
  957.           
  958.    if( temp.cur_baud != Modem.modem[ cur_port ].cur_baud )
  959.          do_redraw( tree, BAUD );
  960.          
  961.    if( temp.cur_parity != Modem.modem[ cur_port ].cur_parity )
  962.        do_redraw( tree, PARITY );
  963.        
  964.    if( temp.cur_bits != Modem.modem[ cur_port ].cur_bits )
  965.        do_redraw( tree, BITSCHAR );
  966.        
  967.    if( temp.cur_flow != Modem.modem[ cur_port ].cur_flow )
  968.        do_redraw( tree, FLOW );
  969.        
  970.    if( temp.cur_stop != Modem.modem[ cur_port ].cur_stop )
  971.        do_redraw( tree, STOPX );
  972. }
  973.  
  974.  
  975.  
  976. void
  977. do_redraw( OBJECT *tree, int obj )
  978. {
  979.    GRECT *xrect;
  980.    GRECT rect;
  981.    GRECT t;
  982.    
  983.    t = ObRect( obj );
  984.    objc_offset( tree, obj, &t.g_x, &t.g_y );   
  985.    
  986.    xrect = (*xcpb->GetFirstRect)( &t );
  987.    while( xrect )
  988.    {
  989.         rect = *xrect;
  990.         Objc_draw( tree, obj, MAX_DEPTH, &rect );
  991.         xrect = (*xcpb->GetNextRect)();
  992.    };   
  993. }
  994.  
  995.  
  996.  
  997.  
  998.  
  999. /* Set_Number_Of_Ports()
  1000.  *==========================================================================
  1001.  * 1) Checks for the presence of an ACTIVE LAN if on a MEGA STE or TT
  1002.  * 2) Sets the Number of Ports available accordingly
  1003.  * 3)         Regular ST        1 ( ALWAYS )
  1004.  *                     LAN OFF    LAN ACTIVE
  1005.  *        MEGA STE           2            2   ( always 2 ports )
  1006.  *        TT               4            3
  1007.  *    This number is shoved into:   int Num_Ports
  1008.  */
  1009. void
  1010. Set_Number_Of_Ports( void )
  1011. {
  1012.      Num_Ports = NORMAL_ST;
  1013.      if( IsTT() )
  1014.          Num_Ports = (( IsLanActive() ) ? ( TT_LAN ) : ( TT_NO_LAN ) );
  1015.  
  1016.      if( IsSTE() )
  1017.      {
  1018. #if 0     
  1019.         Num_Ports = MEGA_STE_PORTS;
  1020. #else        
  1021.         Num_Ports = (( IsLanActive() ) ? ( MEGA_STE_LAN ) : ( MEGA_STE_NO_LAN ) );      
  1022. #endif        
  1023.      }     
  1024. }
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030. /* Get_Active_Port()
  1031.  *==========================================================================
  1032.  * Return the active port ( PORT_A, PORT_B, PORT_C or PORT_D )
  1033.  * On a standard ST, we always return PORT_A ( ST SERIAL )
  1034.  */
  1035. int
  1036. Get_Active_Port( void )
  1037. {
  1038.     int port_mask;
  1039.     
  1040.     if( IsTT() || IsSTE() )
  1041.     {
  1042.          port_mask = Bconmap( INQUIRE_MAP );
  1043.          return( port_mask - MASK_A );    
  1044.     }
  1045.     return( PORT_A );
  1046. }
  1047.  
  1048.  
  1049.  
  1050. /* Set_Active_Port()
  1051.  *==========================================================================
  1052.  * Set the port variables to the NEW port
  1053.  * 1) On a regular ST, the port is ALWAYS the ST SERIAL ( PORT_A )
  1054.  * 2) (TT): If the port is Channel A and the LAN is active, we reset
  1055.  *        the port to ST SERIAL instead.
  1056.  * 3) ( MEGA STE ): if the port is Channel A and the LAN is active, we
  1057.  *            reset the port to ST SERIAL instead
  1058.  * Return: cur_port - 0, 1, 2, 3 with the actual port set to.
  1059.  */
  1060. int
  1061. Set_Active_Port( int port )
  1062. {
  1063.   Set_Number_Of_Ports();
  1064.  
  1065.   if( IsTT() )
  1066.   { 
  1067.  
  1068.      if(( port == PORT_D ) && IsLanActive() )
  1069.          old_port = cur_port = PORT_A; 
  1070.      else
  1071.          old_port = cur_port = port;
  1072.  
  1073.      xbios( 0x2c, ( cur_port + MASK_A ) );  
  1074.      return( cur_port );;  
  1075.   }
  1076.   
  1077.   if( IsSTE() )
  1078.   {
  1079.      if( ( port == PORT_C ) && IsLanActive() )
  1080.     old_port = cur_port = PORT_A;
  1081.      else       
  1082.         old_port = cur_port = port;
  1083.  
  1084.      xbios( 0x2c, ( cur_port + MASK_A ) );  
  1085.      return( cur_port );  
  1086.   }     
  1087.   
  1088.   old_port = cur_port = PORT_A;
  1089.   return( cur_port );
  1090. }
  1091.  
  1092.  
  1093.  
  1094.  
  1095. /* Check_Port_Change()
  1096.  *==========================================================================
  1097.  * When Selecting one of the popup items, the PORT_D status might have
  1098.  * been changed.
  1099.  * On a Standard ST, this can never occur.
  1100.  * On a TT or Mega STE, the port might have the LAN now set to ON.
  1101.  * Therefore, we are going to have to adjust to this.
  1102.  */
  1103. void
  1104. Check_Port_Change( void )
  1105. {
  1106.     int temp_port;
  1107.     
  1108.     temp_port = Get_Active_Port();
  1109.     if( IsTT() && IsLanActive() && ( temp_port == PORT_D ))
  1110.     {
  1111.         Set_Active_Port( temp_port );
  1112.         Redraw_Objects();
  1113.     }
  1114.     
  1115.     if( IsSTE() && IsLanActive() && ( temp_port == PORT_C ) )
  1116.     {
  1117.         Set_Active_Port( temp_port );
  1118.         Redraw_Objects();
  1119.     }               
  1120. }
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126. /* IsLanActive()
  1127.  *=========================================================================
  1128.  * On a Mega STE and on a TT, Channel A can also be the LAN
  1129.  * When the LAN is active, the modem cpx should not read or write to 
  1130.  * Channel A.
  1131.  * Bit 7 on the Sound Chip is the LAN On/Off setting
  1132.  *
  1133.  * Bit 7 == TRUE      ====>     LAN not in use, SO, OK to use
  1134.  * Bit 7 == FALSE     ====>    LAN IN USE, Don't Touch
  1135.  *
  1136.  * Return:   TRUE  - LAN in USE
  1137.  *         FALSE - LAN not in USE
  1138.  */
  1139. BOOLEAN
  1140. IsLanActive( void )
  1141. {
  1142.     char status;
  1143.  
  1144.     if( IsTT() || IsSTE() ) 
  1145.     {    
  1146.        status = Giaccess( 0, 14 );
  1147.        return( !(status & 0x80 ) );
  1148.     }
  1149.     else
  1150.        return( FALSE );   
  1151. }
  1152.  
  1153.  
  1154.  
  1155. /* IsTT()
  1156.  *==========================================================================
  1157.  * Check if value returned from cookie is a TT
  1158.  * TT is 0x2xxxxL
  1159.  */
  1160. BOOLEAN
  1161. IsTT( void )
  1162. {
  1163.     return( ( machine_code >> 16 ) == TT );
  1164. }
  1165.  
  1166.  
  1167.  
  1168.  
  1169. /* IsSTE()
  1170.  *==========================================================================
  1171.  * Returns TRUE or FALSE if this machine is an STE
  1172.  */
  1173. BOOLEAN
  1174. IsSTE( void )
  1175. {
  1176.   return( machine_code == 0x10010L );    /* MEGA STE */
  1177. }
  1178.  
  1179.  
  1180.  
  1181.  
  1182. /*
  1183.  * Open virtual workstation
  1184.  */
  1185. void
  1186. open_vwork( void )
  1187. {
  1188.   int i;
  1189.   
  1190.   if (hcnt == 0) {
  1191.       for (i = 1; i < 10;)
  1192.         work_in[i++] = 1;
  1193.       work_in[0] = Getrez() + 2;
  1194.       work_in[10] = 2;
  1195.       vhandle = xcpb->handle;
  1196.       v_opnvwk(work_in, &vhandle, work_out);
  1197.   }
  1198.   hcnt++;
  1199. }
  1200.  
  1201.  
  1202. /*
  1203.  * Close virtual workstation
  1204.  */
  1205. void
  1206. close_vwork(void)
  1207. {
  1208.     hcnt--;
  1209.     if( !hcnt )
  1210.     {
  1211.      v_clsvwk(vhandle);
  1212.     vhandle = -1;
  1213.     }
  1214. }
  1215.  
  1216.  
  1217.  
  1218. void
  1219. MakeActivator( int xtree, int obj )
  1220. {
  1221.    OBJECT *tree;
  1222.    
  1223.    tree = ( OBJECT *)rs_trindex[ xtree ];
  1224.    
  1225.    ObFlags( obj ) |= IS3DOBJ;
  1226.    ObFlags( obj ) |= IS3DACT;
  1227. }
  1228.